﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ElementClasses;

namespace Organizer
{
    public partial class FormDebug : Form
    {
        public FormDebug()
        {
            InitializeComponent();
        }

        public void AddLog(string title, string txt, bool bTitle, bool bError)
        {
            String s ="";
            if (bTitle) s = "\r\n\r\n *** [" + DateTime.Now.ToString() + "] " + title + "*************\r\n";
            else
            {
                s += "[" + DateTime.Now.ToString() + "] " + title + "\r\n";
                if (txt != "")
                {
                    s += txt + "\r\n";
                    s += "---\r\n";
                }
            }
            txbLog.AppendText(s);
            File.AppendAllText(Gl.dPathDebug + "\\DebugLog "+DateTime.Today.ToString("yyyy.MM.dd")+".log", s);
            if(bError)File.AppendAllText(Gl.dPathDebug + "\\ErrorLog " + DateTime.Today.ToString("yyyy.MM.dd") + ".log", s);
        }

        private void FormDebug_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; WindowState = FormWindowState.Minimized;  Hide(); }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lvExElm.Clear();
            foreach(ExtElementUnit ExU in Gl.exl)
            {
                lvExElm.Items.Add(ExU.ExElm.Name + " >> " + ExU.NetStat.ToString() + " ver=" + ExU.ServVertion);
            }
        }
    }
}
